/*
 * MainFrame.java
 *
 * Created on 20. leden 2009, 19:37
 */

package jmenu.gui;

import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import jmenu.main.Config;
import jmenu.main.FitnessTools;
import jmenu.main.Icons;
import jmenu.main.Settings;

/**
 *
 * @author  Roman
 */
public class MainFrame extends DefaultFrame {

    private String version;
    private Settings settings;

    private ConnectProfileDialog connectdlg;
    private double [] recomendedData;
    
    /** Creates new form MainFrame */
    public MainFrame() {

        this.version = "0.9.1beta";

        this.settings = new Settings();
        this.settings.load();

        Config.setSettings(settings);

        initComponents();

        this.setIconImage(Icons.JMENU_ICON.getImage());

        this.menuTabbedPane.addChangeListener(this.infoJPanel);


        this.connectdlg = new ConnectProfileDialog(this, rootPaneCheckingEnabled);

        this.setLocation(this.settings.getLocX(), this.settings.getLocY());
        this.setSize(this.getWidth() - 12, this.getHeight());
        Config.setMainFrame(this);
        Config.setKernel(new Kernel("mickey.slfree.net", "jmenuro", "bLwuKGQHmmsaLrQFbLwuKGQHmmsaLrQF"));

        this.disableMenuItems();

        this.hideShowPanel();

        if (this.settings.getShowPanel())
        {
            this.showShowPanel();
        }
    }
        
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ToolBarPanel = new javax.swing.JPanel();
        addMenuButton = new javax.swing.JButton();
        deleteMenuButton = new javax.swing.JButton();
        exportFsportButton = new javax.swing.JButton();
        loadMenuButton = new javax.swing.JButton();
        saveMenuButton = new javax.swing.JButton();
        exportHTMLButton = new javax.swing.JButton();
        settingsButton = new javax.swing.JButton();
        showtablesButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        jSeparator5 = new javax.swing.JSeparator();
        infoJPanel = new jmenu.gui.InfoJPanel();
        profileJPanel = new jmenu.gui.ProfileJPanel();
        showPanelToggleButton = new javax.swing.JToggleButton();
        loginLabel = new javax.swing.JLabel();
        loggedUserLabel = new javax.swing.JLabel();
        menuTabbedPane = new jmenu.main.MenuTabbedPane();
        statusPanel1 = new jmenu.gui.StatusPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        profileMenu = new javax.swing.JMenu();
        loginMenuItem = new javax.swing.JMenuItem();
        logoutMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        menuMenu = new javax.swing.JMenu();
        addMenuItem = new javax.swing.JMenuItem();
        deleteMenuItem = new javax.swing.JMenuItem();
        loadMenuItem = new javax.swing.JMenuItem();
        saveMenuItem = new javax.swing.JMenuItem();
        exportMenu = new javax.swing.JMenu();
        htmlMenuItem = new javax.swing.JMenuItem();
        fsportMenuItem = new javax.swing.JMenuItem();
        tablesMenu = new javax.swing.JMenu();
        showtablesMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        helpMenuItem = new javax.swing.JMenuItem();
        siteMenuItem = new javax.swing.JMenuItem();
        jSeparator4 = new javax.swing.JPopupMenu.Separator();
        aboutMenuItem = new javax.swing.JMenuItem();

        setTitle("Jdelníček");
        setMinimumSize(new java.awt.Dimension(100, 100));
        setResizable(false);
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentHidden(java.awt.event.ComponentEvent evt) {
                formComponentHidden(evt);
            }
        });

        ToolBarPanel.setOpaque(false);

        addMenuButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/add-32.png"))); // NOI18N
        addMenuButton.setToolTipText("Přidat nový jídelníček");
        addMenuButton.setMaximumSize(new java.awt.Dimension(40, 40));
        addMenuButton.setMinimumSize(new java.awt.Dimension(40, 40));
        addMenuButton.setPreferredSize(new java.awt.Dimension(40, 40));
        addMenuButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addMenuButtonActionPerformed(evt);
            }
        });

        deleteMenuButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/delete-32.png"))); // NOI18N
        deleteMenuButton.setToolTipText("Smazat jídelníček");
        deleteMenuButton.setPreferredSize(new java.awt.Dimension(73, 73));
        deleteMenuButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteMenuButtonActionPerformed(evt);
            }
        });

        exportFsportButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/exportfsport-32.png"))); // NOI18N
        exportFsportButton.setToolTipText("Export pro F-sport  :-)");
        exportFsportButton.setPreferredSize(new java.awt.Dimension(73, 73));
        exportFsportButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exportFsportButtonActionPerformed(evt);
            }
        });

        loadMenuButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/import-32.png"))); // NOI18N
        loadMenuButton.setToolTipText("Načíst jídelníček");
        loadMenuButton.setPreferredSize(new java.awt.Dimension(73, 73));
        loadMenuButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadMenuButtonActionPerformed(evt);
            }
        });

        saveMenuButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/save-32.png"))); // NOI18N
        saveMenuButton.setToolTipText("Uložit jídelníček");
        saveMenuButton.setPreferredSize(new java.awt.Dimension(73, 73));
        saveMenuButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveMenuButtonActionPerformed(evt);
            }
        });

        exportHTMLButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/exporthtml-32.png"))); // NOI18N
        exportHTMLButton.setToolTipText("Export do HTML");
        exportHTMLButton.setPreferredSize(new java.awt.Dimension(73, 73));
        exportHTMLButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exportHTMLButtonActionPerformed(evt);
            }
        });

        settingsButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/config-32.png"))); // NOI18N
        settingsButton.setToolTipText("Nastavení");
        settingsButton.setPreferredSize(new java.awt.Dimension(73, 73));
        settingsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                settingsButtonActionPerformed(evt);
            }
        });

        showtablesButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/tables-32.png"))); // NOI18N
        showtablesButton.setToolTipText("Otevřít tabulky");
        showtablesButton.setPreferredSize(new java.awt.Dimension(73, 73));
        showtablesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showtablesButtonActionPerformed(evt);
            }
        });

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jSeparator2.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jSeparator5.setOrientation(javax.swing.SwingConstants.VERTICAL);

        javax.swing.GroupLayout ToolBarPanelLayout = new javax.swing.GroupLayout(ToolBarPanel);
        ToolBarPanel.setLayout(ToolBarPanelLayout);
        ToolBarPanelLayout.setHorizontalGroup(
            ToolBarPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ToolBarPanelLayout.createSequentialGroup()
                .addComponent(addMenuButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(deleteMenuButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(2, 2, 2)
                .addComponent(loadMenuButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(saveMenuButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(exportHTMLButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(exportFsportButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(showtablesButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(settingsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(283, Short.MAX_VALUE))
        );
        ToolBarPanelLayout.setVerticalGroup(
            ToolBarPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ToolBarPanelLayout.createSequentialGroup()
                .addGroup(ToolBarPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jSeparator5, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                    .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, ToolBarPanelLayout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 40, Short.MAX_VALUE))
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                    .addComponent(addMenuButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(deleteMenuButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                    .addComponent(loadMenuButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                    .addComponent(saveMenuButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                    .addComponent(exportHTMLButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                    .addComponent(exportFsportButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                    .addComponent(showtablesButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                    .addComponent(settingsButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE))
                .addContainerGap())
        );

        showPanelToggleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/left-16.png"))); // NOI18N
        showPanelToggleButton.setSelected(true);
        showPanelToggleButton.setToolTipText("Zobrazit panel");
        showPanelToggleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        showPanelToggleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showPanelToggleButtonActionPerformed(evt);
            }
        });

        loginLabel.setFont(new java.awt.Font("Tahoma", 1, 12));
        loginLabel.setText("boner");

        loggedUserLabel.setFont(new java.awt.Font("Tahoma", 0, 12));
        loggedUserLabel.setText("přihlášený uživatel:");

        menuTabbedPane.setAutoscrolls(true);
        menuTabbedPane.setMaximumSize(new java.awt.Dimension(857, 636));
        menuTabbedPane.setMinimumSize(new java.awt.Dimension(857, 636));
        menuTabbedPane.setPreferredSize(new java.awt.Dimension(857, 636));
        menuTabbedPane.addContainerListener(new java.awt.event.ContainerAdapter() {
            public void componentAdded(java.awt.event.ContainerEvent evt) {
                menuTabbedPaneComponentAdded(evt);
            }
            public void componentRemoved(java.awt.event.ContainerEvent evt) {
                menuTabbedPaneComponentRemoved(evt);
            }
        });

        profileMenu.setText("Profil");

        loginMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        loginMenuItem.setText("Přihlásit");
        loginMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loginMenuItemActionPerformed(evt);
            }
        });
        profileMenu.add(loginMenuItem);

        logoutMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        logoutMenuItem.setText("Odhlásit");
        logoutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logoutMenuItemActionPerformed(evt);
            }
        });
        profileMenu.add(logoutMenuItem);

        exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        exitMenuItem.setText("Konec");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        profileMenu.add(exitMenuItem);

        jMenuBar1.add(profileMenu);

        menuMenu.setText("Jídelníček");

        addMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/add-16.png"))); // NOI18N
        addMenuItem.setText("Přidat");
        addMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addMenuItemActionPerformed(evt);
            }
        });
        menuMenu.add(addMenuItem);

        deleteMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/delete-16.png"))); // NOI18N
        deleteMenuItem.setText("Smazat");
        menuMenu.add(deleteMenuItem);

        loadMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/import-16.png"))); // NOI18N
        loadMenuItem.setText("Otevřít");
        menuMenu.add(loadMenuItem);

        saveMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/save-16.png"))); // NOI18N
        saveMenuItem.setText("Uložit");
        menuMenu.add(saveMenuItem);

        jMenuBar1.add(menuMenu);

        exportMenu.setText("Export");

        htmlMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        htmlMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/export-16.png"))); // NOI18N
        htmlMenuItem.setText("HTML");
        exportMenu.add(htmlMenuItem);

        fsportMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        fsportMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/export-16.png"))); // NOI18N
        fsportMenuItem.setText("F-sport");
        exportMenu.add(fsportMenuItem);

        jMenuBar1.add(exportMenu);

        tablesMenu.setText("Tabulky");

        showtablesMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
        showtablesMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/tables-16.png"))); // NOI18N
        showtablesMenuItem.setText("Otevřít");
        showtablesMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showtablesMenuItemActionPerformed(evt);
            }
        });
        tablesMenu.add(showtablesMenuItem);

        jMenuBar1.add(tablesMenu);

        helpMenu.setText("Nápověda");

        helpMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0));
        helpMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/help-16.png"))); // NOI18N
        helpMenuItem.setText("Jak to funguje?");
        helpMenu.add(helpMenuItem);

        siteMenuItem.setText("Stránky projektu");
        helpMenu.add(siteMenuItem);
        helpMenu.add(jSeparator4);

        aboutMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jmenu/resources/info-16.png"))); // NOI18N
        aboutMenuItem.setText("O programu");
        aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(aboutMenuItem);

        jMenuBar1.add(helpMenu);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(ToolBarPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(showPanelToggleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(loggedUserLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(loginLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(menuTabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE, 857, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(profileJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(infoJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
            .addComponent(statusPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 1265, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(showPanelToggleButton)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(loggedUserLabel)
                                    .addComponent(loginLabel))
                                .addComponent(ToolBarPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(menuTabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE, 636, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(profileJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(3, 3, 3)
                        .addComponent(infoJPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 520, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-1281)/2, (screenSize.height-768)/2, 1281, 768);
    }// </editor-fold>//GEN-END:initComponents

private void loginMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginMenuItemActionPerformed

    if(Config.getKernel().connect())
    {
        this.connectdlg.setLocationRelativeTo(this);
        this.connectdlg.setVisible(true);
        if (this.connectdlg.getStatus())
        {
            this.enableMenuItems();
            this.updateFitnessProgram();
        }
    }  
}//GEN-LAST:event_loginMenuItemActionPerformed

public void enableMenuItems()
{
    this.loginMenuItem.setEnabled(false);
    this.logoutMenuItem.setEnabled(true);
    this.menuMenu.setEnabled(true);
    this.exportMenu.setEnabled(true);
    this.tablesMenu.setEnabled(true);


    this.addMenuButton.setEnabled(true);
    this.deleteMenuButton.setEnabled(false);
    this.loadMenuButton.setEnabled(true);
    this.showtablesButton.setEnabled(true);
    this.settingsButton.setEnabled(true);


    //this.menuTabbedPane.setEnabled(true);
    
    this.loginLabel.setText(Config.getProfile().getLogin());

    this.profileJPanel.enableProfilePanel();
    this.profileJPanel.setProfile(Config.getProfile());
}

public void disableMenuItems()
{
    this.loginMenuItem.setEnabled(true);
    this.logoutMenuItem.setEnabled(false);
    this.menuMenu.setEnabled(false);
    this.exportMenu.setEnabled(false);
    this.tablesMenu.setEnabled(false);

    
    this.addMenuButton.setEnabled(false);
    this.deleteMenuButton.setEnabled(false);
    this.loadMenuButton.setEnabled(false);
    this.saveMenuButton.setEnabled(false);
    this.exportHTMLButton.setEnabled(false);
    this.exportFsportButton.setEnabled(false);
    this.showtablesButton.setEnabled(false);
    this.settingsButton.setEnabled(false);


    this.menuTabbedPane.removeAll();
    //this.menuTabbedPane.setEnabled(false);

    this.loginLabel.setText("");

    this.profileJPanel.disableProfilePanel();
}

public String getVersion()
{
    return this.version;
}


private void logoutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logoutMenuItemActionPerformed
	
    disableMenuItems();
    Config.setProfile(null);
    this.infoJPanel.setRecomendedData(0, 0, 0, 0);
    if(!Config.getKernel().close())
    {
        //todo
    }
}//GEN-LAST:event_logoutMenuItemActionPerformed

private void showtablesMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showtablesMenuItemActionPerformed
  this.showTables();
}//GEN-LAST:event_showtablesMenuItemActionPerformed

private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
    this.exit();
}//GEN-LAST:event_exitMenuItemActionPerformed

private void addMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addMenuItemActionPerformed
    AddMenuTab();
}//GEN-LAST:event_addMenuItemActionPerformed

private void deleteMenuButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteMenuButtonActionPerformed
    RemoveMenuTab();
}//GEN-LAST:event_deleteMenuButtonActionPerformed

private void showPanelToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showPanelToggleButtonActionPerformed
    if (!this.showPanelToggleButton.isSelected())
        this.showShowPanel();
    else
       this.hideShowPanel();
}//GEN-LAST:event_showPanelToggleButtonActionPerformed

private void exportFsportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportFsportButtonActionPerformed
    this.exportToFsport();
}//GEN-LAST:event_exportFsportButtonActionPerformed

private void loadMenuButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadMenuButtonActionPerformed
    this.loadMenu();
}//GEN-LAST:event_loadMenuButtonActionPerformed

private void saveMenuButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuButtonActionPerformed
    this.saveMenu();
}//GEN-LAST:event_saveMenuButtonActionPerformed

private void exportHTMLButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportHTMLButtonActionPerformed
    this.exportToHTML();
}//GEN-LAST:event_exportHTMLButtonActionPerformed

private void addMenuButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addMenuButtonActionPerformed
    AddMenuTab();
    this.deleteMenuButton.setEnabled(true);
}//GEN-LAST:event_addMenuButtonActionPerformed

private void settingsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_settingsButtonActionPerformed
    SettingsDialog dlg = new SettingsDialog(this, true);
    dlg.setLocationRelativeTo(this);
    dlg.setVisible(true);
}//GEN-LAST:event_settingsButtonActionPerformed

private void formComponentHidden(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentHidden
    this.exit();
}//GEN-LAST:event_formComponentHidden

private void showtablesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showtablesButtonActionPerformed
    showTables();
}//GEN-LAST:event_showtablesButtonActionPerformed

private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
    AboutDialog dlg = new AboutDialog(this, true);
    dlg.setLocationRelativeTo(this);
    dlg.setVisible(true);
}//GEN-LAST:event_aboutMenuItemActionPerformed

private void menuTabbedPaneComponentAdded(java.awt.event.ContainerEvent evt) {//GEN-FIRST:event_menuTabbedPaneComponentAdded
    this.componetManipulation();
}//GEN-LAST:event_menuTabbedPaneComponentAdded

private void menuTabbedPaneComponentRemoved(java.awt.event.ContainerEvent evt) {//GEN-FIRST:event_menuTabbedPaneComponentRemoved
    this.componetManipulation();
}//GEN-LAST:event_menuTabbedPaneComponentRemoved

private void componetManipulation()
{
    if (this.menuTabbedPane.getComponentCount() < 1)
    {
        this.deleteMenuButton.setEnabled(false);
        this.saveMenuButton.setEnabled(false);
        this.exportHTMLButton.setEnabled(false);
        this.exportFsportButton.setEnabled(false);
        this.infoJPanel.setSummaryData(0, 0, 0, 0, 0);
    }
    else
    {
        this.deleteMenuButton.setEnabled(true);
        this.saveMenuButton.setEnabled(true);
        this.exportHTMLButton.setEnabled(true);
        this.exportFsportButton.setEnabled(true);
    }
}


private void saveMenu()
{
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    chooser.setDialogTitle("Uložit jídelníček");
    chooser.setApproveButtonText("Uložit");
    chooser.addChoosableFileFilter(new JMenuFilter());
    chooser.setMultiSelectionEnabled(false);

    int option = chooser.showDialog(Config.getMainFrame(), null);

    if (option == JFileChooser.APPROVE_OPTION)
    {
        String name = chooser.getSelectedFile().getName();

        if (!name.endsWith(".jmn"))
        {
            name = chooser.getSelectedFile().getAbsolutePath().concat(".jmn");
            chooser.setSelectedFile(new File(name));
        }

        MenuPanel mp = (MenuPanel)this.menuTabbedPane.getSelectedComponent();
        if (!mp.saveToFile(chooser.getSelectedFile()))
            JOptionPane.showMessageDialog(Config.getMainFrame(), "Nelze uložit jídelníček do souboru!");
        else
            this.menuTabbedPane.setTitleAt(this.menuTabbedPane.getSelectedIndex(), chooser.getSelectedFile().getName().substring(0, chooser.getSelectedFile().getName().length() - 4 ));
            
    }
}

private void loadMenu()
{
    JFileChooser chooser = new JFileChooser();
    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    chooser.setDialogTitle("Otevřít jídelníček");
    chooser.setApproveButtonText("Otevřít");
    chooser.addChoosableFileFilter(new JMenuFilter());
    chooser.setMultiSelectionEnabled(false);

    int option = chooser.showDialog(Config.getMainFrame(), null);

    if (option == JFileChooser.APPROVE_OPTION)
    {
        String name = chooser.getSelectedFile().getName();

        if (!name.endsWith(".jmn"))
        {
            JOptionPane.showMessageDialog(Config.getMainFrame(), "Soubor není platným formátem aplikace Jdelníček!");
            return;
        }

        MenuPanel mp = new MenuPanel();
        mp.setRecomendedData(this.recomendedData[0], this.recomendedData[1], this.recomendedData[2], this.recomendedData[3]);
        

        if (!mp.loadFromFile(chooser.getSelectedFile()))
            JOptionPane.showMessageDialog(Config.getMainFrame(), "Nelze načíst jídelníček ze souboru!");
        else
            this.menuTabbedPane.add(chooser.getSelectedFile().getName().substring(0, chooser.getSelectedFile().getName().length() - 4 ), mp);
            this.menuTabbedPane.setSelectedIndex(this.menuTabbedPane.getComponentCount() - 1);

    }
}

private void showTables()
{
    TablesFrame tables = new TablesFrame();
    tables.setLocationRelativeTo(this);
    tables.setVisible(true);
}

private void AddMenuTab()
{
    MenuPanel mp = new MenuPanel();
    mp.setRecomendedData(this.recomendedData[0], this.recomendedData[1], this.recomendedData[2], this.recomendedData[3]);
    this.menuTabbedPane.addmenu(mp);
}

private void RemoveMenuTab()
{
    if(this.menuTabbedPane.getSelectedComponent() != null)
        this.menuTabbedPane.remove(this.menuTabbedPane.getSelectedIndex());
}

private void showShowPanel()
{
        this.setSize(this.getWidth() + 400, this.getHeight());
        this.showPanelToggleButton.setIcon(Icons.LEFT_ARROW);
        this.showPanelToggleButton.setSelected(false);
}

private void hideShowPanel()
{
        this.setSize(this.getWidth() - 400, this.getHeight());
        this.showPanelToggleButton.setIcon(Icons.RIHT_ARROW);
        this.showPanelToggleButton.setSelected(true);
}

/**
 * Save setting a close frame.
 */
private void exit()
{
    this.settings.setLocX(this.getX());
    this.settings.setLocY(this.getY());
    this.settings.setShowPanel(!this.showPanelToggleButton.isSelected());
    this.settings.save();
    System.exit(0);
}

private void exportToFsport()
{
    FsportDialog dlg = new FsportDialog(this, true);
    dlg.setLocationRelativeTo(this);
    dlg.setTitle("Export pro F-sport - "+this.menuTabbedPane.getTitleAt(this.menuTabbedPane.getSelectedIndex()));
    dlg.setMenuPanel((MenuPanel)this.menuTabbedPane.getSelectedComponent());
    dlg.setVisible(true);

}

private void exportToHTML()
{
    HTMLDialog dlg = new HTMLDialog(this, true);
    dlg.setLocationRelativeTo(this);
    dlg.setTitle("Export do HTML - "+this.menuTabbedPane.getTitleAt(this.menuTabbedPane.getSelectedIndex()));
    dlg.setMenuPanel((MenuPanel)this.menuTabbedPane.getSelectedComponent());
    dlg.setVisible(true);

}

public void updateFitnessProgram()
{
    this.recomendedData = FitnessTools.getRecomendedData(Config.getProfile().getSex(), this.settings.getProgram() , Config.getProfile().getWeight());
    this.infoJPanel.setRecomendedData(this.recomendedData[0], this.recomendedData[1], this.recomendedData[2], this.recomendedData[3]);

    int count = this.menuTabbedPane.getComponentCount();

    MenuPanel mp;

    for (int i = 0; i < count; i++)
    {
        mp = (MenuPanel)this.menuTabbedPane.getComponentAt(i);
        mp.setRecomendedData(this.recomendedData[0], this.recomendedData[1], this.recomendedData[2], this.recomendedData[3]);
    }
}


private class JMenuFilter extends javax.swing.filechooser.FileFilter
{
    public boolean accept(File file)
    {
        String filename = file.getName();
        return filename.endsWith(".jmn");
    }

    public String getDescription()
    {
        return "Soubory aplikace Jdelníček (*.jmn)";
    }
}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    javax.swing.JPanel ToolBarPanel;
    javax.swing.JMenuItem aboutMenuItem;
    javax.swing.JButton addMenuButton;
    javax.swing.JMenuItem addMenuItem;
    javax.swing.JButton deleteMenuButton;
    javax.swing.JMenuItem deleteMenuItem;
    javax.swing.JMenuItem exitMenuItem;
    javax.swing.JButton exportFsportButton;
    javax.swing.JButton exportHTMLButton;
    javax.swing.JMenu exportMenu;
    javax.swing.JMenuItem fsportMenuItem;
    javax.swing.JMenu helpMenu;
    javax.swing.JMenuItem helpMenuItem;
    javax.swing.JMenuItem htmlMenuItem;
    jmenu.gui.InfoJPanel infoJPanel;
    javax.swing.JMenuBar jMenuBar1;
    javax.swing.JSeparator jSeparator1;
    javax.swing.JSeparator jSeparator2;
    javax.swing.JSeparator jSeparator3;
    javax.swing.JPopupMenu.Separator jSeparator4;
    javax.swing.JSeparator jSeparator5;
    javax.swing.JButton loadMenuButton;
    javax.swing.JMenuItem loadMenuItem;
    javax.swing.JLabel loggedUserLabel;
    javax.swing.JLabel loginLabel;
    javax.swing.JMenuItem loginMenuItem;
    javax.swing.JMenuItem logoutMenuItem;
    javax.swing.JMenu menuMenu;
    jmenu.main.MenuTabbedPane menuTabbedPane;
    jmenu.gui.ProfileJPanel profileJPanel;
    javax.swing.JMenu profileMenu;
    javax.swing.JButton saveMenuButton;
    javax.swing.JMenuItem saveMenuItem;
    javax.swing.JButton settingsButton;
    javax.swing.JToggleButton showPanelToggleButton;
    javax.swing.JButton showtablesButton;
    javax.swing.JMenuItem showtablesMenuItem;
    javax.swing.JMenuItem siteMenuItem;
    jmenu.gui.StatusPanel statusPanel1;
    javax.swing.JMenu tablesMenu;
    // End of variables declaration//GEN-END:variables

}
